package top.eggcode.system.client.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import top.eggcode.common.mvc.Result;
import top.eggcode.common.mvc.ResultWrapper;
import top.eggcode.system.client.DictClientService;
import top.eggcode.system.client.model.Word;

import java.util.List;

@Component
public class DictClientFactory implements FallbackFactory<DictClientService> {

    private static final Logger logger = LoggerFactory.getLogger(DictClientFactory.class);

    @Override
    public DictClientService create(Throwable cause) {
        logger.error("词典服务调用失败:{}", cause.getMessage());
        return new DictClientService() {

            @Override
            public Result<List<Word>> getWords(String code) {
                return ResultWrapper.failure("数据获取失败:{}" + cause.getMessage());
            }
        };
    }
}
